<script type="text/javascript" src="<?=base_url()?>resource/plugins/My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript" src="<?=base_url()?>resource/js/layer/layer.js"></script>
<script type="text/javascript" src="<?=base_url()?>resource/js/layer/extend/layer.ext.js"></script>
<script type="text/javascript">
    $(function(){
        trbgmoves('#d3dff2');
        $('#moneyType').val('<?=$searchData['moneyType']?>');
        $('#country_code').val('<?=$searchData['country_code']?>');
        $('#currency').val('<?=$searchData['currency']?>');
    });
    function AddDepositRecord(){
        var accountArr=['parisa','lyb','Trista','prezwang','dhhtgaogao','vivian','吴丹丹','Monty','guoyang','homguang','林平平','chuyilin','邱远琴','Romy','sony'];
        var accounts="<?=$this->users['account']?>";
        var num =$.inArray(accounts,accountArr);
        if(num >= 0) {
            $("select[data-edit-select]").val('');
            $('.currency').val('');
            $('.transaction').val('');
            $('.money').val('');
            $('.orderId').val('');
            $('.customers_currency').val('');
            $('.country_code').val('');
            $('.grandTotalMerchant').text('');
            $('.grandTotalBrand').text('');
            $(".popupBg,.popupContainer").addClass("active");
            $("select[data-edit-select]").filterSelect();
        }else{
            alert('此权仅对特定人员开放！');
        }
    }
    //币种验证

    function currencyPd(obj){
       var customers_id=obj.val(),
           currency_this = obj.parents(".recordTable").find(".currency"),
           currencyText_this = obj.parents(".recordTable").find(".currencyText"),
           customers_currency = obj.parents(".recordTable").find(".customers_currency");
        currency_this.val('');
        currencyText_this.text('');
        customers_currency.val('');
        if(customers_id != '') {
            var index=layer.load(2);
            $.post("<?=blang_url('ajax/ajax/currencyPd')?>", {'customers_id': customers_id}, function (data) {
                if (data) {
                    layer.close(index);
                    if (data == 'null') {
                        alert('当前客户尚未设置币种，请通知相关人员');
                    } else {
                        currency_this.val(data);
                        console.log(data);
                        currencyText_this.text(data);
                        customers_currency.val(data);
                    }
                }
            });
        }
    }
    //获取订单信息
    function getOrderInfo(obj){
        var orderId = obj.parents(".recordTable").find(".orderId");
        var country_code = obj.parents(".recordTable").find(".country_code");
        var currency = obj.parents(".recordTable").find(".currency");
        var grandTotalMerchant = obj.parents(".recordTable").find(".grandTotalMerchant");
        var grandTotalBrand = obj.parents(".recordTable").find(".grandTotalBrand");
        var order_num=orderId.val();
        var index=layer.load(2);
        $.post("<?=blang_url('ajax/ajax_two/GetOrderInfo')?>",{'order_num':order_num},function(data){
            if(data){
                layer.close(index);
                var orderData=JSON.parse(data);
                if(orderData['point']){
                    country_code.val(orderData['point']);
                    currency.val(orderData['currency_code']);
                    grandTotalMerchant.text(orderData['grandTotalMerchant']);
                    grandTotalBrand.text(orderData['grandTotalBrand']);
                }else{
                    alert('维修单号不存在!请从新输入');
                }
            }
        })
    }
    //提交验证
    function Sub(obj,type){
        var customers_id = $.trim(obj.parents(".recordTable").find("select[data-edit-select]").val()),
            currency=$.trim(obj.parents(".recordTable").find(".currency").val()),
            transactionId=$.trim(obj.parents(".recordTable").find(".transaction").val()),
            money=$.trim(obj.parents(".recordTable").find(".money").val()),
            orderId=$.trim(obj.parents(".recordTable").find(".orderId").val()),
            customers_currency=$.trim(obj.parents(".recordTable").find(".customers_currency").val()),
            country_code=$.trim(obj.parents(".recordTable").find(".country_code").val());
        if(customers_id==''){
            alert('客户不能为空');
            return false;
        }
        if(customers_currency==''){
            alert('客户币种尚未设置,请先设置');
            return false;
        }
        if(transactionId == ''){
            alert('交易号不能为空！');
            return false;
        }
        if(currency==''){
            alert('币种不能为空');
            return false;
        }
        if(isNaN(money) || money=='' || money<=0 ){
            alert('金额必须是非零数字');
            return false;
        }
        if(type==2 && orderId==''){
            alert('订单号不能为空');
            return false;
        }
        if(type==2 && country_code==''){
            alert('站点不能为空');
            return false;
        }
        if(!confirm('所有信息已经确认无误了吗？当前币种转换'+currency+'=>'+customers_currency+',务必核对清楚')){
            return false;
        }
    }
    /**
     * 设置银行科目
     */
    function setBankSubject(){
        //定义银行科目
        var bankSubject=new Array();
        bankSubject['de']={'1':'1221.08.05','2':'195-2809'};
        bankSubject['es']={'1':'1221.08.06','2':'51-6179'};
        bankSubject['ru']={'1':'1221.08.07','2':'140-0288'};
        bankSubject['us']={'1':'1221.08.04.02','2':'202-1535'};
        bankSubject['gb']={'1':'1221.08.03','2':'203-5666'};
        bankSubject['sz']={'1':'','2':''};
        var country_code=$('#country_code').val();
        var payment_type=$('#payment_type').val();
        var key_code="'"+country_code+"'";
        var key_pay="'"+payment_type+"'";
        $('#bank_subject').val(bankSubject[country_code][payment_type]);
    }
</script>

<!--菜单 start-->
<?php $this->load->view('defaults/common/left');?>
<!--菜单 end-->
<div id="content">
  <div class="page-header">
    <div class="container-fluid">
      <h1><?=lang('menu_yhgl')?></h1>
      <?=$this->breadcrumb->generateHTML();?>
    </div>
  </div>
  <div class="container-fluid">
    <div class="panel panel-default">
      <div class="panel-heading">
        <h3 class="panel-title"><i class="fa fa-list"></i><?=lang('menu_ckjllb')?></h3>
      </div>
      <div class="panel-body">
        <div class="well" style="padding:0 19px;">
          <div class="row">
            <form action="<?=blang_url('users/member/depositrecordlist/')?>" method="post" enctype="multipart/form-data" name="searchform" >
                <div class="col-sm-3">
                    <div class="form-group">
                        <label class="control-label">客户名/订单号/交易信息</label>
                        <input class="form-control" type="text" size="60" name="keyword" value="<?=$searchData['keyword']?>" placeholder="客户名/订单号/交易信息">
                    </div>
                </div>
                <div class="col-sm-3">
                    <div class="form-group">
                        <label class="control-label">类型</label>
                        <select class="form-control" name="moneyType" id="moneyType">
                            <option value="">-全部-</option>
                            <option value="add">充值记录</option>
                            <option value="reduce">扣款记录</option>
                        </select>
                    </div>
                </div>
                <div class="col-sm-3">
                    <div class="form-group">
                        <label class="control-label">站点</label>
                        <select class="country_code form-control" id="country_code"  name="country_code">
                            <option value="">-请选择-</option>
                            <?php foreach($pointList as $row){?>
                                <option value="<?=$row['point']?>"><?=$row['point']?></option>
                            <?php }?>
                        </select>
                    </div>
                </div>
                <div class="col-sm-3">
                    <div class="form-group">
                        <label class="control-label">币种</label>
                         <select class="form-control" id='currency' name="currency" >
                            <option value="">全部</option>
                            <option value="CNY">CNY</option>
                            <option value="EUR">EUR</option>
                            <option value="USD">USD</option>
                            <option value="GBP">GBP</option>
                            <option value="RUB">RUB</option>
                        </select>
                    </div>
                </div>
                 <div class="col-sm-12" style="padding-bottom: 19px;">
                    <input class="btn btn-primary pull-right" style="margin: 0 0 0 10px;" type="submit" value=" 查 询 ">
                    <input class="btn btn-oms pull-right" style="margin: 0 0 0 10px;" type="button" onclick="AddDepositRecord()" value="创建资金记录">
                    <a class="btn btn-oms pull-right" href="<?=blang_url('users/member/ExportFundsData'.$str)?>"><i class="fa fa-download"></i>&nbsp;导出数据</a>
                </div>
            </form>
          </div>
        </div>

        <div class="table-responsive">
            <table class="table table-bordered table-hover oms-table">
              <thead>
                <tr>
                  <td class="text-left">CNY</td>
                  <td class="text-left">EUR</td>
                  <td class="text-right">GBP</td>
                  <td class="text-right">USD</td>
                </tr>
              </thead>
              <tbody>
               <tr>
                    <td class="text-left">
                        <span style="color: #00ee00">充:<?=$capitalDetails['addTotal']['CNY']?:0?></span>
                        <span style="color: #ff0000">扣:<?=$capitalDetails['subtractTotal']['CNY']?:0?></span>
                        <span style="color: #009900">总:<?=$capitalDetails['total']['CNY']?:0?></span>
                    </td>
                    <td class="text-left">
                        <span style="color: #00ee00">充:<?=$capitalDetails['addTotal']['EUR']?:0?></span>
                        <span style="color: #ff0000">扣:<?=$capitalDetails['subtractTotal']['EUR']?:0?></span>
                        <span style="color: #009900">总:<?=$capitalDetails['total']['EUR']?:0?></span>
                    </td>
                    <td class="text-right">
                        <span style="color: #00ee00">充:<?=$capitalDetails['addTotal']['GBP']?:0?></span>
                        <span style="color: #ff0000">扣:<?=$capitalDetails['subtractTotal']['GBP']?:0?></span>
                        <span style="color: #009900">总:<?=$capitalDetails['total']['GBP']?:0?></span>
                    </td>
                    <td class="text-right">
                        <span style="color: #00ee00">充:<?=$capitalDetails['addTotal']['USD']?:0?></span>
                        <span style="color: #ff0000">扣:<?=$capitalDetails['subtractTotal']['USD']?:0?></span>
                        <span style="color: #009900">总:<?=$capitalDetails['total']['USD']?:0?></span>
                    </td>
                </tr>
            </tbody>
            </table>

            <table class="table table-bordered table-hover oms-table">
              <thead>
                <tr>
                    <th class="text-left">id</th>
                    <th class="text-left">交易信息</th>
                    <th class="text-left">客户名</th>
                    <th class="text-left">变更额度</th>
                    <th class="text-right">币种</th>
                    <th class="text-right">变更时间</th>
                    <th class="text-right">变更单号</th>
                    <!--<th>状态</th>-->
                    <!--<th>操作</th>-->
                </tr>
              </thead>
              <tbody>
                <?php if($depositrecordlist): foreach ($depositrecordlist as $key=>$v):?>
                <tr>
                    <td class="text-left"><?=$v['id']?></td>
                    <td class="text-left"><?=$v['transactionId']?></td>
                    <td class="text-left"><?=$v['name']?></td>
                    <td class="text-left"><?=$v['money']>0?"<span style='color: #00CC00'>".$v['money']."</span>":"<span style='color: #ff0000'>".$v['money']."</span>"?></td>
                    <td class="text-right"><?=$v['currency']?></td>
                    <td class="text-right"><?=date('Y-m-d H:i:s',$v['time'])?></td>
                    <td class="text-right"><?=$v['orderId']?></td>
                    <!--<td>
                        <?php
/*                                            switch($v['status']){
                                case '1':
                                    echo "<span style='color: blue'>已通过</span>";
                                    break;
                                case '2':
                                    echo "<span style='color: red'>已拒绝</span>";
                                    break;
                                default:
                                    echo "<span style='color: #888888'>待审核</span>";
                            }
                        */?>
                    </td>
                    <td>
                        <a href="<?/*=blang_url('users/member/auditdeposit/'.$v['id'].'/'.str_replace('==','',base64_encode($v['email'])).'/'.$v['name'].'/'.$v['money']).'/1'*/?>" onclick="return confirm('你确定数据已经核对无误了吗？')"><input type="button" value="通过" <?/*=$v['status']!=0?'disabled':''*/?>></a>
                        <a href="<?/*=blang_url('users/member/auditdeposit/'.$v['id'].'/'.str_replace('==','',base64_encode($v['email'])).'/'.$v['name'].'/'.$v['money']).'/2'*/?>" onclick="return confirm('你确定数据已经核对无误了吗？')"><input type="button" value="拒绝" <?/*=$v['status']!=0?'disabled':''*/?>></a>
                    </td>-->
                </tr>
                <?php endforeach; else:?>
                    <tr><th colspan="7" class="emptyNumber"><?=lang('public_mygdsj')?>....</th></tr>
                <?php endif; ?>
            </tbody>
            </table>
            <?php if($pageShow):?>
            <div class="page">
                <?=$pageShow?>
            </div>
            <?php endif;?>
          </div>
      </div>
    </div>
    </div>

    <div class="popupBg"></div>
    <div class="popupContainer layui-layer-tab" style="width:720px;height:350px;margin:-125px 0px 0px -360px;">
    <div class="layui-layer-title popupController">
        <span class="layui-layer-tabnow">充值</span><span class="">扣款</span>
    </div>
    <div class="popupContent">
        <div class="ct_content active">
            <form action="<?=blang_url('users/member/AddDepositRecord')?>" method="post">
                <table class="recordTable" cellspacing="0">
                    <tr>
                        <th>客户：</th>
                        <td style="overflow: visible;position: relative;">
                            <select name="customers_id" data-edit-select="1" style="width: 400px;">
                                <option value="">-请选择-</option>
                                <?php foreach($customersList as $row){?>
                                    <option value="<?=$row['id']?>"><?=$row['name']?></option>
                                <?php }?>
                            </select>
                            currency:<span class="currencyText"></span>
                            <input type="hidden" class="customers_currency" name="customers_currency">
                        </td>
                    </tr>
                    <tr>
                        <th>交易信息：</th>
                        <td><input type="text" class="transaction" name="transactionId" size="50"></td>
                    </tr>
                    <tr>
                        <th>币种：</th>
                        <td>
                           <select class="currency" name="currency" style="width: 200px;">
                                <option value="">-请选择-</option>
                                <option value="CNY">CNY</option>
                                <option value="USD">USD</option>
                                <option value="GBP">GBP</option>
                                <option value="RUB">RUB</option>
                                <option value="EUR">EUR</option>
                            </select>
                            <span style="color: #ff0000">选择币种和客户币种不一致将会自动进行汇率转换</span>
                        </td>
                    </tr>
                    <tr>
                        <th>金额：</th>
                        <td>
                            <input type="text" class="money" name="money" >
                        </td>
                    </tr>
                    
                    <tr>
                        <td></td>
                        <td>
                            <input type="submit" value=" 提 交 " onclick="return Sub($(this),1)" style="width: 200px;">
                        </td>
                    </tr>
                </table>
            </form>
        </div>
        <div class="ct_content">
            <form action="<?=blang_url('users/member/AddDepositRecord')?>" method="post">
                <table class="recordTable" cellspacing="0">
                    <tr>
                        <th>客户：</th>
                        <td style="overflow: visible;position: relative;">
                            <select name="customers_id" data-edit-select="1" style="width: 400px;">
                                <option value="">-请选择-</option>
                                <?php foreach($customersList as $row){?>
                                    <option value="<?=$row['id']?>"><?=$row['name']?></option>
                                <?php }?>
                            </select>
                            currency:<span class="currencyText"></span>
                            <input type="hidden" class="customers_currency" name="customers_currency">
                        </td>
                    </tr>
                    <tr>
                        <th>交易信息：</th>
                        <td><input type="text" class="transaction" name="transactionId" size="50"></td>
                    </tr>
                    <tr>
                        <th>币种：</th>
                        <td>
                           <select class="currency"  name="currency" style="width: 200px;">
                                <option value="">-请选择-</option>
                                <option value="CNY">CNY</option>
                                <option value="USD">USD</option>
                                <option value="GBP">GBP</option>
                                <option value="RUB">RUB</option>
                                <option value="EUR">EUR</option>
                            </select>
                            <span style="color: #ff0000">选择币种和客户币种不一致将会自动进行汇率转换</span>
                        </td>
                    </tr>
                    <tr>
                        <th>金额：</th>
                        <td>
                            <input type="text" class="money" name="money" >
                            商家支付总额：<span class="grandTotalMerchant" style="color: #ff0000"></span>
                            品牌支付总额：<span class="grandTotalBrand" style="color: #ff0000"></span>
                        </td>
                    </tr>
                    <tr>
                        <th>订单号：</th>
                        <td>
                            <input type="text" class="orderId"   name="orderId" >
                            <a href="javaScript:void(0)" onclick="getOrderInfo($(this))">获取订单信息</a>
                        </td>
                    </tr>
                    <tr>
                        <th>站点：</th>
                        <td>
                            <select class="country_code"  name="country_code" id="country_code" onchange="setBankSubject()">
                                <option value="">-请选择-</option>
                                <?php foreach($pointList as $row){?>
                                    <option value="<?=$row['point']?>"><?=$row['point']?></option>
                                <?php }?>
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <th>收款方式：</th>
                        <td>
                            <select name="payment_type" id="payment_type" onchange="setBankSubject()">
                                <option value="0">-请选择-</option>
                                <option value="1">现金</option>
                                <option value="2">银行</option>
                            </select>
                            银行科目：
                            <input type="text" name="bank_subject" id="bank_subject">
                        </td>
                    </tr>
                    <tr>
                        <td></td>
                        <td>
                            <input type="submit" value=" 提 交 " onclick="return Sub($(this),2)" style="width: 200px;">
                        </td>
                    </tr>
                </table>
            </form>
        </div>
    </div>
   <span class="layui-layer-setwin">
    <a class="layui-layer-ico layui-layer-close1 popupClose" href="javascript:;"></a>
    </span>

    <script type="text/javascript">
        (function($){
            $(function(){
                $("select[data-edit-select]").on("change",function(){
                    currencyPd($(this));
                });
            });
        })(jQuery);
    </script>
</div>
</div>



